---
import { SITE } from "@config";
import Posts from "@layouts/Posts.astro";
import getSortedPosts from "@utils/getSortedPosts";
import getPageNumbers from "@utils/getPageNumbers";

import { getCollection } from "astro:content";

const posts = await getCollection("blog");

const sortedPosts = getSortedPosts(posts);

const totalPages = getPageNumbers(sortedPosts.length);

const paginatedPosts = sortedPosts.slice(0, SITE.postPerPage);
---

<Posts posts={paginatedPosts} pageNum={1} totalPages={totalPages.length} />
